package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.vo.exhaustGasWarningConfig.ExhaustGasWarningConfigAddDTO;
import com.bf.electroplating.pojo.vo.exhaustGasWarningConfig.ExhaustGasWarningConfigQueryDTO;
import com.bf.electroplating.pojo.vo.exhaustGasWarningConfig.ExhaustGasWarningConfigUpdateDTO;
import com.bf.electroplating.pojo.vo.exhaustGasWarningConfig.ExhaustGasWarningConfigVO;
import com.bf.electroplating.service.IExhaustGasWarningConfigService;
import com.bf.electroplating.pojo.vo.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;

/**
 * 废气处理设施监控预警设置控制器
 */
@Slf4j
@RestController
@RequestMapping("/exhaust-gas-warning-config")
@Tag(name = "废气处理设施监控预警设置", description = "废气处理设施监控预警设置相关接口")
@Validated
public class ExhaustGasWarningConfigController {

    @Autowired
    private IExhaustGasWarningConfigService exhaustGasWarningConfigService;

    @PostMapping("/pageList")
    @Operation(summary = "分页查询废气预警配置", description = "分页查询废气处理设施监控预警设置列表")
    public ResultVO<Page<ExhaustGasWarningConfigVO>> pageList(@Valid @RequestBody ExhaustGasWarningConfigQueryDTO queryDTO) {
        log.info("分页查询废气预警配置，查询条件：{}", queryDTO);
        
        try {
            Page<ExhaustGasWarningConfigVO> result = exhaustGasWarningConfigService.pageList(queryDTO);
            return ResultVO.ok(result);
        } catch (Exception e) {
            log.error("分页查询废气预警配置失败", e);
            return ResultVO.fail("查询失败：" + e.getMessage());
        }
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "获取废气预警配置详情", description = "根据ID获取废气预警配置详细信息")
    public ResultVO<ExhaustGasWarningConfigVO> getDetail(
            @Parameter(description = "主键ID", required = true)
            @PathVariable @NotBlank(message = "ID不能为空") String id) {
        log.info("获取废气预警配置详情，ID：{}", id);
        
        try {
            ExhaustGasWarningConfigVO result = exhaustGasWarningConfigService.getDetail(id);
            if (result == null) {
                return ResultVO.fail("数据不存在");
            }
            return ResultVO.ok(result);
        } catch (Exception e) {
            log.error("获取废气预警配置详情失败", e);
            return ResultVO.fail("查询失败：" + e.getMessage());
        }
    }



    @PostMapping("/update")
    @Operation(summary = "更新废气预警配置", description = "更新废气处理设施监控预警设置")
    public ResultVO<Boolean> updateConfig(@Valid @RequestBody ExhaustGasWarningConfigUpdateDTO updateDTO) {
        log.info("更新废气预警配置，数据：{}", updateDTO);
        
        try {
            Boolean result = exhaustGasWarningConfigService.updateConfig(updateDTO);
            if (result) {
                return ResultVO.ok(true, "更新成功");
            } else {
                return ResultVO.fail("更新失败");
            }
        } catch (Exception e) {
            log.error("更新废气预警配置失败", e);
            return ResultVO.fail("更新失败：" + e.getMessage());
        }
    }






}
